package com.pro.springbootshop.service.impl;

import com.pro.springbootshop.entity.ExtendOrders;
import com.pro.springbootshop.entity.Orders;
import com.pro.springbootshop.mapper.ExtendOrdersMapper;
import com.pro.springbootshop.mapper.OrderMapper;
import com.pro.springbootshop.service.ExtendOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ExtendOrdersServiceImpl implements ExtendOrdersService {
    public ExtendOrdersMapper extendOrdersMapper;
    @Autowired
    public void setUserMapper (ExtendOrdersMapper extendOrdersMapper) {
        this.extendOrdersMapper = extendOrdersMapper;
    }
    public OrderMapper orderMapper;
    @Autowired
    public void setUserMapper (OrderMapper orderMapper) {
        this.orderMapper = orderMapper;
    }
    @Override
    public String changOrdersByExtendOrders(Integer ordersId) {
        List<ExtendOrders> extendOrdersList=extendOrdersMapper.selectOrderByOrdersId(ordersId);
        for(ExtendOrders extendOrders: extendOrdersList){
            Orders orders=extendOrders.getOrders();
            orders.setOrderState(3);
            int i=orderMapper.updateById(orders);
            if(i<0){
                return "修改失败";
            }
        }
        return "修改成功";
    }

    @Override
    public List<ExtendOrders> getExtendOrders(Integer ordersId) {
        List<ExtendOrders> extendOrdersList=extendOrdersMapper.selectOrderByOrdersId(ordersId);
        for(ExtendOrders extendOrders:extendOrdersList){
            extendOrders.getOrders().getWares().setPictureList(extendOrders.getOrders().getWares().getWaresPicture().split(";"));
        }
        return extendOrdersList;
    }

    @Override
    public Integer getExtendOrdersId(Integer orderId) {
        return extendOrdersMapper.getOrdersId(orderId);
    }
}
